Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

460
Views
ReferenceError: la ventana no está definida, considere usar el entorno de prueba "jsdom" (broma V28)

Quisiera ayuda para resolver este error.

ingrese la descripción de la imagen aquí

Estoy usando Jest V28.0.0.

Así es como se ven el script de prueba y las devDependencies de mi paquete.json

 "scripts":{ ..., "test": "jest --env=node --watchAll --coverage --verbose", }, "devDependencies": { ... "@babel/preset-env": "^7.16.11", "@testing-library/jest-dom": "^4.2.4", "@testing-library/react": "^9.3.0", "@types/jest": "^27.4.1", "babel-jest": "^28.0.0", "jest": "^28.0.0", "jest-environment-jsdom": "^28.0.1", "jsdom": "^19.0.0", } }

También tengo un archivo jest.config.js que se ve así

 module.exports = { roots: ['<rootDir>/tests/'], testEnvironment: 'jsdom', testMatch: ['**/?(*.)+(test).js'], transform: { '^.+\\.js?$': 'babel-jest', }, moduleNameMapper: { ... }, }

Mi archivo de prueba real se ve así

 import React from 'react' import { render, cleanup, screen } from '@testing-library/react' import renderer from 'react-test-renderer' import '@testing-library/jest-dom' /** * @jest-environment jsdom */ //components import MyComponent from '../../../../src/website/Components/MyComponent' test('should have the Add recipients text label', () => { const addRecipientsLabel = screen.getByTestId('label-element') expect(true).toBe(true) render(<MyComponent />) expect(addRecipientsLabel).toHaveTextContent('Add Recipients') })
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debe incluir @jest-environment en la parte superior del archivo. Por encima incluso de las importaciones.

https://jestjs.io/docs/configuration#testenvironment-string

P.ej.:

 /** * @jest-environment jsdom */ import React from 'react' //components import MyComponent from '...' test('should have the Add recipients text label', () => { // test })
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!